@extends('layouts.admin.application')

@section('content')
    <div class="main-content">
        <div class="col-xs-12">
            <div class="breadcrumbs" id="breadcrumbs">
                <ul class="breadcrumb">
                    <li><i class="icon-home home-icon"></i><a href="#">首页</a></li>
                    <li>系统管理</li>
                </ul>
            </div>
            <div class="table-responsive">
                <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
                    <div class="row">

                        @include('layouts.partials._flash')

                        <div class="col-sm-2">
                            <div id="sample-table-2_length" class="dataTables_length">
                                <a href="{{route('system.permission.create')}}" class="btn btn-sm btn-primary">新增</a>
                                <a href="javascript:void(0);" class="btn btn-sm btn-purple" id="show_all">展开所有</a>
                            </div>
                        </div>
                    </div>
                    <table id="sample-table-2"
                           class="table table-striped table-bordered table-hover dataTable del-table"
                           aria-describedby="sample-table-2_info">
                        <thead>
                        <tr role="row">
                            <th>编号</th>
                            <th>菜单名称</th>
                            <th>节点名称</th>
                            <th>图标</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        @foreach($permissions as $permission)
                            <tr class="xParent" data-id="{{$permission->id}}" id="row_{{$permission->id}}">
                                <td>{{$permission->id}}</td>
                                <td>{{$permission->label}}</td>
                                <td>{{$permission->name}}</td>
                                <td>{{$permission->icon}}</td>
                                <td>
                                    <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                        <a class="green" href="{{route('system.permission.edit', $permission->id)}}"><i class="icon-pencil bigger-130"></i></a>
                                        <a class="red" href="{{route('system.permission.destroy', $permission->id)}}"
                                           data-method="delete" data-token="{{csrf_token()}}"
                                           data-confirm="确定要删除此条记录么?">
                                            <i class="icon-trash bigger-130"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>

                            @foreach($permission->children as $child)
                                <tr class="xChildren child_row_{{$child->id}}" data-id="{{$child->id}}"
                                    style="display: none;">
                                    <td>{{$child->id}}</td>
                                    <td>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--{{$child->label}}
                                    </td>
                                    <td>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--{{$child->name}}
                                    </td>
                                    <td>{{$child->icon}}</td>
                                    <td>
                                        <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                            <a class="green" href="{{route('system.permission.edit', $child->id)}}"><i class="icon-pencil bigger-130"></i></a>
                                            <a class="red" href="{{route('system.permission.destroy', $child->id)}}"
                                               data-method="delete" data-token="{{csrf_token()}}"
                                               data-confirm="确定要删除此条记录么?">
                                                <i class="icon-trash bigger-130"></i>
                                            </a>
                                        </div>
                                    </td>
                                </tr>

                                @foreach($child->children as $c)
                                    <tr class="xChildren child_row_{{$c->id}}" data-id="{{$c->id}}"
                                        style="display: none;">
                                        <td>{{$c->id}}</td>
                                        <td>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--{{$c->label}}
                                        </td>
                                        <td>
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|--{{$c->name}}
                                        </td>
                                        <td>{{$c->icon}}</td>
                                        <td>
                                            <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                                <a class="green" href="{{route('system.permission.edit', $c->id)}}"><i class="icon-pencil bigger-130"></i></a>
                                                <a class="red" href="{{route('system.permission.destroy', $c->id)}}"
                                                   data-method="delete" data-token="{{csrf_token()}}"
                                                   data-confirm="确定要删除此条记录么?">
                                                    <i class="icon-trash bigger-130"></i>
                                                </a>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                            @endforeach
                        @endforeach

                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>
        $(function () {
            //展开与折叠表格
            $("tr.xParent").dblclick(function () {
                $(this).toggleClass();
                $(".child_" + this.id).toggle();
            });

            $("#show_all").click(function () {
                $("tr.xParent").toggleClass();
                $("tr.xChildren").toggle('am-active');
            });
        })
    </script>
@endsection